package crawlertest.crawler;

import java.util.concurrent.TimeUnit;

import org.jsoup.nodes.Entities.EscapeMode;

public class Main 
{
	public static void main(String[] args)
	{
		int i;
		for(i=1;i<=500;i++)
		{
			ShareVars.es.execute(new CThread(i,ShareVars.lock1,ShareVars.empty,
					ShareVars.lock2,ShareVars.lock3,ShareVars.lock4));
		}
		ShareVars.num=501;
		System.out.println("500线程创建完毕准备唤醒empty");
		ShareVars.lock1.lock();
		ShareVars.workurls.offer("http://www.pcgames.com.cn");
		ShareVars.empty.signalAll();
		ShareVars.lock1.unlock();
		
		while(true)
		{
			System.out.println("当前下载html数为" +ShareVars.count);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
			}
			if(ShareVars.count>=5000)
			{
				
				ShareVars.finish=1;
				break;
			}
			
		}
		
		
	
			try {
				ShareVars.es.shutdown();
				while(ShareVars.es.awaitTermination(1L, TimeUnit.SECONDS)==false)
				{
					ShareVars.lock1.lock();
					ShareVars.empty.signalAll();
					ShareVars.lock1.unlock();
					
				}
				System.out.println("finish!!!");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
			//	e.printStackTrace();
			}	
	}//main
		
		
	
}//class
